/* clock */

#include "SFML/Audio.hpp"
#include "SFML/Graphics.hpp"
#include <iostream>
#include <ctime>
#include <sstream>

int main()
{
				/*-*-*-*-terminal-*-*-*-*/
	
	/*timer*/
	std::stringstream tim;
	char timer[4];
	std::cout << "Timer: ";
	std::cin >> timer;
	tim << timer;	

				/*-*-*-*-soft-*-*-*-*/
	
	/*window*/
	sf::RenderWindow window(sf::VideoMode(250.f, 130.f), "bedbug");

	/*font*/
	sf::Font cherry;
	cherry.loadFromFile("/home/terrible_byte/.local/share/fonts/cherry-13-b.otb");

	/*items*/
		/*rectangle - forms*/
	sf::RectangleShape rectangle(sf::Vector2f(240.f, 120.f));
	rectangle.setFillColor(sf::Color::Black);
	rectangle.setOutlineThickness(5);
	rectangle.setOutlineColor(sf::Color::White);
	rectangle.setPosition(5.0f, 5.0f);

	/*text for time*/
	sf::Text text("Time: ", cherry);
	text.setCharacterSize(13);
	text.setFillColor(sf::Color::Red);
	text.setStyle(sf::Text::Italic);
	text.setPosition(5.0f, 5.0f);

	/*text for timer*/
	sf::Text timertext("Timer: ", cherry);
	timertext.setCharacterSize(13);
	timertext.setFillColor(sf::Color::Red);
	timertext.setStyle(sf::Text::Italic);
	timertext.setPosition(5.0f, 20.0f);

	sf::Text settimer(tim.str(), cherry);
	settimer.setCharacterSize(13);
	settimer.setFillColor(sf::Color::Red);
	settimer.setPosition(100.0f, 20.0f);


	/*sound*/
	sf::SoundBuffer signal;
	signal.loadFromFile("clocksound.ogg");
	sf::Sound sound(signal);

	/*main cycle*/
	while (window.isOpen())
	{
		/*time*/
		time_t now = time(NULL);
		struct tm *now_tm;
		std::stringstream hm;

		now_tm = localtime(&now);
		if (now_tm->tm_min < 10){
			hm<<now_tm->tm_hour<<":0"<<now_tm->tm_min;
		} else{
			hm<<now_tm->tm_hour<<":"<<now_tm->tm_min;
		}

		sf::Text ti(hm.str(), cherry);
		ti.setCharacterSize(13);
		ti.setFillColor(sf::Color::Red);
		ti.setPosition(100.0f, 5.0f);

		/*alarm*/
		if (tim.str() == hm.str()){
			sound.play();
		}

		/*draw*/
		window.clear();
		window.draw(rectangle);
		window.draw(text);
		window.draw(ti);
		window.draw(timertext);
		window.draw(settimer);
		window.display();

	}

	/*end*/

	return 0;
}
